let john = {name: "John", age: 25};
let pete = {name: "pete", age: 30};
let mary = {name: "Mary", age: 28};

let arr = [pete, john, mary];

sortByAge(arr);

alert(arr[0].name);
alert(arr[1].name);
alert(arr[2].name);

function compareByAge(a, b) {
    if (a.age > b.age) {
        return 1;
    } else if (a.age == b.age) {
        return 0;
    } else {
        return -1;
    }
}

function sortByAge(arr) {
    arr.sort(compareByAge);
    // 简单箭头函数的方法
    // arr.sort((a, b) => a.age - b.age);
}